/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.DAO.mysqlDAO;

import assignment_cp3120.DAO.DepartureLocationDAO;
import assignment_cp3120.DAO.DestinationDAO;
import assignment_cp3120.DAO.Factory.DAOFactory;
import assignment_cp3120.DAO.FlightDAO;
import assignment_cp3120.DAO.GST_PromoDAO;
import assignment_cp3120.DAO.TicketDAO;
import assignment_cp3120.DAO.TransactionDAO;
import assignment_cp3120.DAO.UserDAO;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 * This is the data access object factory for mysql.
 * This class holds the driver, url, username and password for the database.
 * It also create connection function and getters for the DAOs
 * @author Richard Irons
 */
public class MysqlDA0Factory extends DAOFactory{
    //connection information
    /**
     * Driver for mysql
     */
    public static final String DRIVER = "com.mysql.jdbc.Driver";
    /**
     * Location of the database
     */
    public static final String URL = "jdbc:mysql://dunk.cs.jcu.edu.au/3120S109g09";
    //login to database info
    private static final String USERNAME = "3120S109g09";
    private static final String PASSWORD = "f8004ad17c";
    
    /**
     * This function creates a connection to the database. 
     * If an error occured the function will return null.
     * If there is no error this function will return the connection
     * @return
     * If an error occured, null else the connection
     */
    public static Connection createConnection(){
         Connection con = null;
         try{
             //initialise the driver class
            Class.forName(DRIVER);
            //connect to the database
            con = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        }catch(Exception e){return null;}        
        return con;
    }
    /**
     * Getter to create a UserDAO
     * @return
     * new MysqlUserDAO
     */
    public UserDAO getUserDAO(){
        return new MysqlUserDAO();
    }
    /**
     * Getter to create a TicketDAO
     * @return
     * new MysqlTicketDAO
     */
    public TicketDAO getTicketDAO(){
        return new MysqlTicketDAO();
    }
    /**
     * Getter to create a FlightDAO
     * @return
     * new MysqlFlightDAO
     */
    public FlightDAO getFlightDAO(){
        return new MysqlFlightDAO();
    }
    /**
     * Getter to create TransactionDAO
     * @return
     * new MysqlTransactionDAO
     */
    public TransactionDAO getTransactionDAO(){
        return new MysqlTransactionDAO();
    }
    /**
     * Getter to create a DepartureLocationDAO
     * @return
     * new MysqlDepartureLocatonDAO
     */
    public DepartureLocationDAO getDepartureLocationDAO(){
        return new MysqlDepartureLocatonDAO();
    }
    /**
     * Getter to create a DestinationDAO
     * @return
     * new MysqlDestinationDAO
     */
    public DestinationDAO getDestinationDAO(){
        return new MysqlDestinationDAO();
   }

    @Override
    public GST_PromoDAO getGST_PromoDAO() {
        return new MysqlGST_promoDAO();
    }
                                        
}
